﻿@*A object display template for a table*@
@using System.Text.RegularExpressions;

@if (Model == null) {
    @ViewData.ModelMetadata.NullDisplayText
}
else if(ViewData.TemplateInfo.TemplateDepth > 1) {
    @ViewData.ModelMetadata.SimpleDisplayText
}
else {
    <table class="properties" >        
        <thead>
            <tr>
                <th class="name">Name</th>
                <th class="value">Value</th>
            </tr>
        </thead>
        <tbody>
            @foreach(var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm) && !pm.IsComplexType)) {
                if(prop.HideSurroundingHtml) {
                    @Html.Display(prop.PropertyName)
                }
                else {    
                     <tr>
                        <td>
                            <div class="display-label" >
                                @*Nicer display names with splitted camel casing*@
                                @(Regex.Replace(prop.GetDisplayName(),"([A-Z])"," $1", RegexOptions.Compiled).Trim())                                
                            </div>
                        </td>
                        <td>
                            <div class="display-field">
                                @Html.Display(prop.PropertyName)                                
                            </div>
                        </td>
                     </tr>
                }
            }
        </tbody>
    </table>   
    
}